#!/bin/bash

# android-components
read -d '' p << 'EOF' || true
if (m/const\\s+val\\s+VERSION\\s+=\\s+"([^"]+)"/) {
  print $1;
  exit;
}
EOF
needed=$(cat buildSrc/src/main/java/AndroidComponents.kt | perl -ne "$p")
current='[% pc("android-components", "var/android_components_version") %]'
check_update_needed android-components "$needed" "$current"


# targetSdkVersion
read -d '' p << 'EOF' || true
if (m/const\\s+val\\s+targetSdkVersion\\s+=\\s+([^"]+)/) {
  print $1;
  exit;
}
EOF
needed=$(cat buildSrc/src/main/java/Config.kt | perl -ne "$p")
current=30
check_update_needed targetSdkVersion "$needed" "$current"


# compileSdkVersion
read -d '' p << 'EOF' || true
if (m/const\\s+val\\s+compileSdkVersion\\s+=\\s+([^"]+)/) {
  print $1;
  exit;
}
EOF
needed=$(cat buildSrc/src/main/java/Config.kt | perl -ne "$p")
current=31
check_update_needed compileSdkVersion "$needed" "$current"


# minSdkVersion
read -d '' p << 'EOF' || true
if (m/const\\s+val\\s+minSdkVersion\\s+=\\s+([^"]+)/) {
  print $1;
  exit;
}
EOF
needed=$(cat buildSrc/src/main/java/Config.kt | perl -ne "$p")
current=21
check_update_needed minSdkVersion "$needed" "$current"


# gradle
read -d '' p << 'EOF' || true
if (m|distributionUrl=https\\\\://services.gradle.org/distributions/gradle-(.*)-bin.zip|) {
  print $1;
  exit;
}
EOF
needed=$(cat gradle/wrapper/gradle-wrapper.properties | perl -ne "$p")
current='[% c("var/gradle_version") %]'
check_update_needed gradle "$needed" "$current"


# android-gradle-plugin
read -d '' p << 'EOF' || true
if (m/const\\s+val\\s+android_gradle_plugin\\s+=\\s+"([^"]+)"/) {
  print $1;
  exit;
}
EOF
needed=$(cat buildSrc/src/main/java/Dependencies.kt | perl -ne "$p")
current='7.0.0'
check_update_needed android-gradle-plugin "$needed" "$current"
